{extend name='public/base' /}

{block name="content"}
<style type="text/css">

	.banjies{
		color: #ffffff;
		font-size: 14px;
		background-color: #2d8cf0;
		padding: 3px;
		 width: 60px;
		 border-radius: 5px;
		 text-align: center;
		line-height: 24px;
		display: inline-block;
	}
	.tanchu{
		    position: absolute;
		    top: 170px;
		    left: 440px;
		    background-color: #fff;
		    border: #ccc solid 1px;
		    width: 230px;
		    border-radius: 10px;
	}
	</style>
<div class="layui-col-md12">

    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">日期 ：</label>-->
<!--                        <div class="layui-input-inline">-->
<!--                            <input name="company" class="layui-input" value="" type="text" placeholder="请输入公司名称">-->
<!--                        </div>-->
<!--                    </div>-->

                    <div class="layui-inline">
                        <label class="layui-form-label">日期范围</label>
                        <div class="layui-inline" id="test6">
                            <div class="layui-input-inline">
                                <input type="text" autocomplete="off" name="Date[startDate]" id="startDate" class="layui-input" placeholder="开始日期">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <input type="text" autocomplete="off"  name="Date[endDate]" id="endDate" class="layui-input" placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">商户：</label>
                        <div class="layui-input-inline">
                            <select name="merchant_id" id="merchant_id" lay-verify="required" lay-search="">
                                <option value="0" ></option>
                                {volist name="merchant_list" id="t"}
                                {if empty($t.name)||$t.name=='-'}
                                <option value="{$t.id}" >{$t.company} - {$t.code}</option>
                                {else/}
                                <option value="{$t.id}" >{$t.name} - {$t.code}</option>
                                {/if}
                                {/volist}
                            </select>
                        </div>
                    </div>
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">订单号：</label>-->
<!--                        <div class="layui-input-inline">-->
<!--                            <input name="order_sn" class="layui-input" id="title" value="" type="text"-->
<!--                                   placeholder="请输入订单号">-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search" lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="layui-icon layui-icon-refresh"></i>{:__('Reset')}</button>
                        <button class="layui-btn layui-bg-black iconfont icon-daochu layui-btn-sm" id="join">导出</button>
<!-- id="export" -->
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>
    <div style="display: none">
        <table id="table">
        </table>
    </div>
</div>
<div>
	
	
</div>

          <div class="tanchu" style="display: none;" id="tanchu">

		     <div class="uni-card uni-border" class="uni-card--full uni-card--shadow" style=" margin: 18px 0 0 0;" >
		 <span>会计期间：</span>
				<textarea id="textarea" rows="3" cols="20" style="resize: none;border-radius: 3px;height: 24px;width: 130px;border: #ccc solid 0.5px;color: #968e8e;line-height: 24px;position: absolute;top: 20px;"placeholder="请输入会计期间"></textarea>
                 <div style="width: 160px;height: 50px;margin: 30px 0 0 42px;"> <span class="banjies" lay-submit id="export" style="float: left;">确定</span><span class="banjies" lay-submit lay-filter="exit" style="float: right;">取消</span></div>
		    </div>
		</div>


{/block}

{block name="js"} <!--js处理区-->


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
<!--        <button type="button" lay-event="add" class="layui-btn {:node('Admin/addAdmin')} layui-btn-sm">添加安保人员</button>-->
<!--        <button type="button" lay-event="del" class="layui-btn {:node('Admin/del')} layui-btn-sm layui-btn-danger">-->
<!--            删除安保人员-->
<!--        </button>-->
        <button type="button" lay-event="carryDown" class="layui-btn {:node('Admin/carryDown')} layui-btn-sm layui-btn-danger">
            结转
        </button>
        <button type="button" lay-event="reload" class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
    </div>
</script>
<script type="text/html" id="operationTpl">
    {{# if(d.id==0){ }}
    不可编辑
    {{# }else{ }}
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Admin/addAdmin')}" data-title="编辑"
       lay-event="edit"><i class="layui-icon"></i></a>
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('Admin/del')}" data-title="删除"
       lay-event="del"><i class="layui-icon "></i></a>
    {{# } }}
</script>
<!--<script src="https://www.layuicdn.com/extend/excel/1.6.5/layui_exts/excel.min.js">-->
</script>
<script>
    layui.use(['element', 'table', 'form', 'jquery', 'excel','lucky', 'opTable','laydate'], function () {
        var excel = layui.excel;
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        var opTable = layui.opTable;
        var laydate = layui.laydate;
        form.render();
        laydate.render({
            elem: '#startDate'
            ,type: 'datetime',
			trigger: 'click'
        });
        laydate.render({
            elem: '#endDate'
            ,type: 'datetime',
			trigger: 'click'
        });


         $('#join').on('click',function () {
                console.log('弹层该出现了')
                   document.getElementById("tanchu").style.display ="block";
                 });
		 form.on('submit(exit)', function (obj) {
			console.log('点击关闭')
				   document.getElementById("tanchu").style.display ="none";
				   });


        //导出事件
        $('#export').on('click',function () {
            var merchant_id = $('#merchant_id').val() ;
			var remarkVal= $("#textarea").val()
            var startDate = $('#startDate').val() ;
            var endDate = $('#endDate').val() ;
            var data = {
                'merchant_id' : merchant_id ,
                'startDate' :  startDate ,
                'endDate' :  endDate ,
                'export' :  1,
				'remarkVal':remarkVal,
            } ;
            var url = "{:url('export')}" + "&merchant_id=" + merchant_id +'&startDate='+startDate+ "&endDate=" + endDate + "&export=" + 1+"&remarkVal="+remarkVal ;
            //console.log(url);
            window.open(url);
            // //使用ajax请求获取所有数据
            // $.ajax({
            //     url: "{:url('index')}",
            //     type: 'post',
            //     data: data,
            //     async: false,
            //     dataType: 'json',
            //     success: function (res) {
            //         document.getElementById("tanchu").style.display ="none";
            //         var liul = [] ;
            //
            //         liul[0] = [
            //             '公司','记账日期','会计期间','凭证类型','凭证号','币种','分录号','对方分录号','主表信息','附表信息','原币','本位币','报告币','主表金额系数','附表金额系数','性质','核算项目1','编码1','名称1','核算项目2','编码2','名称2','核算项目3','编码3','名称3','核算项目4','编码4','名称4','核算项目5','编码5','名称5','核算项目6','编码6','名称6','核算项目7','编码7','名称7','核算项目8','编码8','名称8'
            //         ];
            //         excel.exportExcel({
            //             凭证: res.data,
            //             现金流量: liul
            //         }, '财务报表.xlsx', 'xlsx', {
            //             extend: {
            //                 // extend 中可以指定某个 sheet 的属性，如果不指定 sheet 则所有 sheet 套用同一套属性
            //             },
            //             writeOpt: {
            //                 bookSST: true,
            //             }
            //         });
            //
			// 		 // document.getElementById("tanchu").style.display ="none";
            //         // table.exportFile('exportTable', res.data, 'xls');
            //     }
            // });
        });

        //导出时阻止页面刷新
        $(".layui-form").submit(function (e) {
            e.preventDefault();
        })
        var myTables = table.render({
            elem: '#table_id',
            url: "{:url('index')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: [],
            even: true, //开启隔行背景
            id: 'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'last'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 20
                , limits: [10, 20, 30, 50]
            },
              // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {title: '公司', field: 'company'},
                {title: '记账日期', field: 'jz_time'},
                {title: '业务日期', field: 'jz_time'},
                {title: '凭证号', field: 'pingz'},
                {title: '分录号', field: 'fenlu'},
                {title: '摘要', field: 'zaiyao'},
                {title: '科目', field: 'cost_sn'},
                {title: '原币金额', field: 'money'},
                {title: '借方金额', field: 'j_money'},
                {title: '贷方金额', field: 'd_money'},
                // {title: '制单人', field: 'admin'},
                {title: '核算项目1', field: 'xm1'},
                {title: '编码1', field: 'sn1'},
                {title: '名称1', field: 'name1'},
                {title: '核算项目2', field: 'xm2'},
                {title: '编码2', field: 'sn2'},
                {title: '结转收入对应的科目', field: 'carry_down_sn'},
                {title: '科目名称', field: 'carry_down_name'},
                {title: '税率', field: 'tax_rate'},
                {title: '税金科目', field: 'tax_sn'},
                {title: '科目名称', field: 'tax_name'},
            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id = parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent === "edit") {
                var urls = "{:url('add')}?id=" + _id;
                lucky.CreateOpenForm("编辑", urls);

            } else if (layEvent === "del") {
                lucky.FormatData(_id, "{:url('del')}");
            }
        });


        table.on('toolbar(table_id)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if (obj.event === "add") {
                lucky.CreateOpenForm("添加 ", "{:url('add')}");
                return false;
            } else if (obj.event === "close") {
                opTables.closeAll();
            } else if (obj.event === "open") {
                opTables.openAll();
            } else if (obj.event === "reload") {
                lucky.CreateReload();
            } else if (obj.event === "del") {
                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", {time: 1500});
                    return false;
                }
                lucky.FormatData(id, "{:url('del')}");
                return false;
            }else if (obj.event === "carryDown") {  // 转结存
                layer.confirm('确认结转？',  {icon: 3, title:'提示'}, function(index) {
                    layer.close(index);
                    $.ajax({
                        url: "{:url('carryDown')}",
                        type: "POST",
                        async: true,
                        dataType: "json",
                        data: {},
                        error: function(error) {
                            layer.msg("服务器错误或超时");
                            return false;
                        },
                        success: function(data) {
                            if (data.code == 1) {
                                lucky.layerMsg(data.msg, 15, function() {
                                    lucky.CreateReload(table_id);
                                });
                            } else {
                                lucky.layerMsg(data.msg, 1, function() {
                                    setTimeout(function() {
                                        lucky.CreateReload(table_id); //重载表格数据
                                    }, 500);
                                });

                            }
                        }
                    });
                });
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script>
{/block}
